﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class UserControl_ControlDisplayUser : System.Web.UI.UserControl
{
    ClassExecute.ClassExecute dt;
    string str = webapp4U.Configuration.CurrentConnectionString;
    static string error = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
           

            if (Session["db"] != null)
            {
                Session["db"] = null;
            }
             if (Session["db1"] != null)
            {
                Session["db1"] = null;
            }
            if (Session["user"] == null)
            {
                Response.Redirect(webapp4U.Globals.ApplicationPath + "Default.aspx");
               
            }
            else
            {
                lblUser.Text = "Chào mừng: " + Session["user"].ToString();
                if (Session["UserType"].ToString() == "dev")
                {
                }
                else
                {
                    dt = new ClassExecute.ClassExecute();
                    string sPath = HttpContext.Current.Request.Url.AbsolutePath.Substring(1);
                    //Nếu chạy ở local thì thêm "Source"/Pages/Form/Default.aspx"
                    if ((sPath == "Pages/Form/Default.aspx") || (sPath == "Pages/Management/Default.aspx") || (sPath == "Pages/SetSKUForTDVFinal/Default.aspx") || (sPath == "Pages/SetRouteTDVFinal/Default.aspx") || (sPath == "Pages/DetailPhanChiaDS/Default.aspx"))
                    {
                    }
                    else
                    {
                        int i = dt.ExecuteSQl_int(str, "k_checkPagePermission", CommandType.StoredProcedure, ref error,
                            new SqlParameter("@PageURL", sPath),
                            new SqlParameter("@TypeID", Session["UserType"].ToString()));
                        if (i == 2)
                        {
                            Response.Redirect(webapp4U.Globals.ApplicationPath + "Default.aspx");
                        }
                    }
                }
            }
           
                
            
        }
    }
}